package com.example.market_management.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.market_management.mapper.productMapper;
import com.example.market_management.model.Product;
import com.example.market_management.model.vo.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("product")
@CrossOrigin
public class productController {

    @Autowired
    private productMapper productMapper;


    /**
     * 通过产品类型查询产品 不输入则为查询全部产品
     * @param productType
     * @return
     */
    @GetMapping("/byType")
    private CommonResult byTypeQuery( String productType){
       List<Product> productList=productMapper.byTypeQuery(productType);
       return CommonResult.success(productList);
    }


    /**
     * 通过产品名查询产品  模糊查询
     * @param productName
     * @return
     */
    @GetMapping("/queryByName")
    private CommonResult queryByName( String productName){
         List<Product> productList=productMapper.queryByName(productName);
         return CommonResult.success(productList);
    }


    /**
     * 通过产品Id查询产品
     * @param productId
     * @return
     */
    @GetMapping("/queryById/{productId}")
    private CommonResult queryById(@PathVariable  String  productId){
       Product product= productMapper.selectById(productId);
       return CommonResult.success(product);
    }
}
